//
//  MovieCollectionViewCell.m
//  DSYDouban
//
//  Created by dllo on 16/1/7.
//  Copyright © 2016年 lanou3g. All rights reserved.
//

#import "MovieCollectionViewCell.h"
#import "UIImageView+WebCache.h"
#import "MovieModel.h"


@interface MovieCollectionViewCell ()

@property (nonatomic, retain) UIImageView *imgView;

@property (nonatomic, retain) UILabel *movieNameLabel;

@end

@implementation MovieCollectionViewCell

- (void)dealloc
{
    [_imgView release];
    [_movieNameLabel release];
    
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubviews];
    }
    return self;
}

- (void)setModel:(MovieModel *)model
{
    if (_model != model) {
        [_model release];
        _model = [model retain];
        
        [self refreshUI];
    }
}


- (void)refreshUI {
    
    _movieNameLabel.text = _model.title;
    
    [_imgView sd_setImageWithURL:[NSURL URLWithString:[_model.images objectForKey:@"large"]]];
}


- (void)createSubviews {
    self.imgView = [[UIImageView alloc] init];
    [self.contentView addSubview:_imgView];
    [_imgView release];
    
    self.movieNameLabel = [[UILabel alloc] init];
    [self.contentView addSubview:_movieNameLabel];
    [_movieNameLabel release];
    
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    _imgView.frame = CGRectMake(0, 0, layoutAttributes.size.width, layoutAttributes.size.height - 35);
    
    _movieNameLabel.frame = CGRectMake(0, layoutAttributes.size.height - 35, layoutAttributes.size.width, 35);
    _movieNameLabel.numberOfLines = 0;
    _movieNameLabel.font = [UIFont systemFontOfSize:12.0];
    _movieNameLabel.textAlignment = NSTextAlignmentCenter;
}




@end
